package cn.org.eshow.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * 订单表
 */
@Entity
@Table(name = "product_order")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ProductOrder extends BaseObject implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;//订单ID

    @Column(name = "add_time")
    private Date addTime = new Date();// 添加时间

    @Column(name = "update_time")
    private Date updateTime = new Date();// 更新时间

    @Column(name = "category", length = 20)
    private String category;// 分类（用户订单）

    @Column(name = "no", length = 20)
    private String no;// 订单号

    @Column
    private Double price = 0.00;// 总计价格（不含优惠券）
    @Column
    private Double pay = 0.00;// 支付人民币价格(用户实际付款金额)

    @Column(name = "orig_price")
    private Double origPrice = 0.00;// 总计原价

    @Column
    private Double discount = 0.00;// 优惠金额

    @Column
    private Double coupon = 0.00;// 红包金额

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_coupon_id")
    private UserCoupon userCoupon;// 用户红包ID

    @Column(name = "payment", length = 11)
    private Integer payment;//付款方式（0支付宝支付，1微信支付 ,2余额支付）

    @Column(name = "state")
    private Integer state=0;//订单状态（0待付款，1已完成（已验收），-1已取消，2待联系（已付款） ,  3处理中   ）

    @Column(name = "handle_state")
    private Integer handleState = 0;//处理状态   0待量房（已联系）    9待处理（等待用户补单）   1 待施工（已量房）  2待验收（已施工） 3已验收

    @Column(name = "statements", length = 200)
    private String statements;//订单当前状态说明


    @Column(name = "comment_state")
    private Integer commentState = 0;//评价状态（0未评价，1已评价）

    @Column(name = "refund_state")
    private Integer refundState = 0;// 退款状态（0无退款，1已退款，2退款中 ,3退款申请中）

    @Column(name = "refund_amount")
    private Double refundAmount;//(原路返回)退款金额

    @Column(name = "offline_refund")
    private Double offlineRefund;//线下退款金额

    @Column
    private Boolean settlement = Boolean.FALSE;// 是否结算

    @Column
    private String reason;//原因

    @Column(length = 400)
    private String remark;// 备注(用户留言)

    @Column
    private String address;// 收货地址

    @Column(name = "addr_name", length = 30)
    private String addrName;// 收货人姓名

    @Column(name = "addr_mobile", length = 20)
    private String addrMobile;// 收货人手机号码

    @Column
    private String callback;// 支付回调

    @Column
    private Boolean enabled = Boolean.TRUE;// 是否可用

    @Column
    private String province;// 省

    @Column
    private String city;// 城市

    @Column
    private String district;// 区县

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "additional_order_id")
    private AdditionalOrder additionalOrder;// 补单ID

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private User user;// 用户

    @JsonIgnore
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "productOrder")
    private Set<OrderItem> orderItems = new HashSet<OrderItem>(0);

    public ProductOrder() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public Double getOrigPrice() {
        return origPrice;
    }

    public void setOrigPrice(Double origPrice) {
        this.origPrice = origPrice;
    }

    public Double getDiscount() {
        return discount;
    }

    public void setDiscount(Double discount) {
        this.discount = discount;
    }

    public Double getCoupon() {
        return coupon;
    }

    public void setCoupon(Double coupon) {
        this.coupon = coupon;
    }

    public Double getPay() {
        return pay;
    }

    public void setPay(Double pay) {
        this.pay = pay;
    }


    public Integer getPayment() {
        return payment;
    }

    public void setPayment(Integer payment) {
        this.payment = payment;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public String getStatements() {
        return statements;
    }

    public void setStatements(String statements) {
        this.statements = statements;
    }


    public Integer getCommentState() {
        return commentState;
    }

    public void setCommentState(Integer commentState) {
        this.commentState = commentState;
    }

    public Integer getRefundState() {
        return refundState;
    }

    public void setRefundState(Integer refundState) {
        this.refundState = refundState;
    }

    public Double getRefundAmount() {
        return refundAmount;
    }

    public void setRefundAmount(Double refundAmount) {
        this.refundAmount = refundAmount;
    }

    public Boolean getSettlement() {
        return settlement;
    }

    public void setSettlement(Boolean settlement) {
        this.settlement = settlement;
    }


    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAddrName() {
        return addrName;
    }

    public void setAddrName(String addrName) {
        this.addrName = addrName;
    }

    public String getAddrMobile() {
        return addrMobile;
    }

    public void setAddrMobile(String addrMobile) {
        this.addrMobile = addrMobile;
    }


    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getDistrict() {
        return district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }


    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public UserCoupon getUserCoupon() {
        return userCoupon;
    }

    public void setUserCoupon(UserCoupon userCoupon) {
        this.userCoupon = userCoupon;
    }

    public Integer getHandleState() {
        return handleState;
    }

    public void setHandleState(Integer handleState) {
        this.handleState = handleState;
    }

    public Double getOfflineRefund() {
        return offlineRefund;
    }

    public void setOfflineRefund(Double offlineRefund) {
        this.offlineRefund = offlineRefund;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public String getCallback() {
        return callback;
    }

    public void setCallback(String callback) {
        this.callback = callback;
    }

    public AdditionalOrder getAdditionalOrder() {
        return additionalOrder;
    }

    public void setAdditionalOrder(AdditionalOrder additionalOrder) {
        this.additionalOrder = additionalOrder;
    }

    public Set<OrderItem> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(Set<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }

    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

        ProductOrder pojo = (ProductOrder) o;
        if (id != null ? !id.equals(pojo.id) : pojo.id != null)
            return false;
        if (addTime != null ? !addTime.equals(pojo.addTime) : pojo.addTime != null)
            return false;
        if (updateTime != null ? !updateTime.equals(pojo.updateTime) : pojo.updateTime != null)
            return false;
        if (category != null ? !category.equals(pojo.category) : pojo.category != null)
            return false;
        if (no != null ? !no.equals(pojo.no) : pojo.no != null)
            return false;
        if (price != null ? !price.equals(pojo.price) : pojo.price != null)
            return false;
        if (pay != null ? !pay.equals(pojo.pay) : pojo.pay != null)
            return false;
        if (payment != null ? !payment.equals(pojo.payment) : pojo.payment != null)
            return false;
        if (state != null ? !state.equals(pojo.state) : pojo.state != null)
            return false;
        if (statements != null ? !statements.equals(pojo.statements) : pojo.statements != null)
            return false;
        if (refundState != null ? !refundState.equals(pojo.refundState) : pojo.refundState != null)
            return false;
        if (settlement != null ? !settlement.equals(pojo.settlement) : pojo.settlement != null)
            return false;
        if (remark != null ? !remark.equals(pojo.remark) : pojo.remark != null)
            return false;
        if (address != null ? !address.equals(pojo.address) : pojo.address != null)
            return false;
        if (addrName != null ? !addrName.equals(pojo.addrName) : pojo.addrName != null)
            return false;
        if (addrMobile != null ? !addrMobile.equals(pojo.addrMobile) : pojo.addrMobile != null)
            return false;
        if (callback != null ? !callback.equals(pojo.callback) : pojo.callback != null)
            return false;
        if (enabled != null ? !enabled.equals(pojo.enabled) : pojo.enabled != null)
            return false;
        if (province != null ? !province.equals(pojo.province) : pojo.province != null)
            return false;
        if (city != null ? !city.equals(pojo.city) : pojo.city != null)
            return false;
        if (district != null ? !district.equals(pojo.district) : pojo.district != null)
            return false;
        if (additionalOrder != null ? !additionalOrder.equals(pojo.additionalOrder) : pojo.additionalOrder != null)
            return false;
        if (user != null ? !user.equals(pojo.user) : pojo.user != null)
            return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = result + (id != null ? id.hashCode() : 0);
        result = 31 * result + (addTime != null ? addTime.hashCode() : 0);
        result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0);
        result = 31 * result + (category != null ? category.hashCode() : 0);
        result = 31 * result + (no != null ? no.hashCode() : 0);
        result = 31 * result + (price != null ? price.hashCode() : 0);
        result = 31 * result + (pay != null ? pay.hashCode() : 0);
        result = 31 * result + (payment != null ? payment.hashCode() : 0);
        result = 31 * result + (state != null ? state.hashCode() : 0);
        result = 31 * result + (statements != null ? statements.hashCode() : 0);
        result = 31 * result + (refundState != null ? refundState.hashCode() : 0);
        result = 31 * result + (settlement != null ? settlement.hashCode() : 0);
        result = 31 * result + (remark != null ? remark.hashCode() : 0);
        result = 31 * result + (address != null ? address.hashCode() : 0);
        result = 31 * result + (addrName != null ? addrName.hashCode() : 0);
        result = 31 * result + (addrMobile != null ? addrMobile.hashCode() : 0);
        result = 31 * result + (callback != null ? callback.hashCode() : 0);
        result = 31 * result + (enabled != null ? enabled.hashCode() : 0);
        result = 31 * result + (province != null ? province.hashCode() : 0);
        result = 31 * result + (city != null ? city.hashCode() : 0);
        result = 31 * result + (district != null ? district.hashCode() : 0);
        result = 31 * result + (additionalOrder != null ? additionalOrder.hashCode() : 0);
        result = 31 * result + (user != null ? user.hashCode() : 0);
        return result;
    }

    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", this.id)
                .append("addTime", this.addTime)
                .append("updateTime", this.updateTime)
                .append("category", this.category)
                .append("no", this.no)
                .append("price", this.price)
                .append("pay", this.pay)
                .append("payment", this.payment)
                .append("state", this.state)
                .append("statements", this.statements)
                .append("refundState", this.refundState)
                .append("settlement", this.settlement)
                .append("remark", this.remark)
                .append("address", this.address)
                .append("addrName", this.addrName)
                .append("addrMobile", this.addrMobile)
                .append("callback", this.callback)
                .append("enabled", this.enabled)
                .append("province", this.province)
                .append("city", this.city)
                .append("district", this.district)
                .append("additionalOrder", this.additionalOrder)
                .append("user", this.user)
                .toString();
    }
}
